package org.ascollada.core
{
	import org.ascollada.core.ns.collada;
	
	public class DaeAnimation extends DaeElement
	{
		use namespace collada;
		
		public var channels :Array;
		public var samplers :Array;
		
		public function DaeAnimation(document:DaeDocument, element:XML=null)
		{
			super(document, element);
		}
		
		public override function read(element:XML):void
		{
			if(element.channel.length() == 0 || element.channel.length() != element.sampler.length())
			{
				// invalid animation channel, or simply a container
				return;
			}
			
			super.read(element);
			
			this.channels = new Array();
			this.samplers = new Array();

			for(var i:int = 0; i < element.channel.length(); i++)
			{
				var channel :XML = element.channel[i];
				var samplerID :String = channel.@source.split("#")[1];
				var sampler :XML = element.sampler.(@id == samplerID)[0];

				if(!sampler) continue;
				if(!channel.@target.length()) continue;
				
				var smp :DaeSampler = new DaeSampler(this.document, sampler);
				
				this.samplers.push(smp);
				
				var ch :DaeChannel = new DaeChannel(this.document, smp, channel);
				
				if(ch.type < 0)
					continue;
				
				smp.channel = ch;
				
				this.channels.push(ch);
				
				trace(ch);
			}
		}
	}
}